#include "BFSTravelBinaryTree.h"
// queue 实现 BFS
void BFSTravelBinaryTree(TreeNode* root, vector<int>& cache) {
  if (!root)
    return;
  else {
    queue<TreeNode*> q;
    q.push(root);
    TreeNode* tmp;
    while (q.size()) {
      tmp = q.front();
      q.pop();
      cache.push_back(tmp->val);
      if (tmp->left) q.push(tmp->left);
      if (tmp->right) q.push(tmp->right);
    }
  }
}
vector<int> BFSTravelBinaryTree(TreeNode* root) {
  vector<int> res;
  BFSTravelBinaryTree(root, res);
  return res;
}
